define(["../points.js", "../modules/popimg.js"], function(points){
    var conf = this;
    var groupMap = {};
    conf.pointMap = {};  //wg01=>point
    conf.pointGroups = [];  //整体外观=>{label, name, list:[point]}
    var groupIdx = 1;
    points.forEach(function(p){
        var id = p[2];
        var label = p[0];
        var groupLabel = p[1];
        var level = p[3];
        var desc = p[4].replace(/\r/g, '').split(/\n/).map(function(line){
            line = line.replace(/^\d*：/,'');
            return line ? '<li>'+line+'</li>' : '';
        });
        var url = "images/"+id+".jpg";
        var point = {
            id: id,
            label: label,
            weight: level,
            desc: '<ol>'+desc.join("")+'</ol>',
            refurl: url,
            status: 0
        };
        if(!groupMap[groupLabel]){
            groupMap[groupLabel] = {
                label: (groupIdx++) + '.' + groupLabel,
                slabel: groupLabel,
                name: id.substr(0,2),
                list: []
            };
            conf.pointGroups.push(groupMap[groupLabel]);
        }
        point.basename = groupMap[groupLabel].label + '/' + id + '.jpg';
        groupMap[groupLabel].list.push(point);
        conf.pointMap[id] = point;
    });

    $$.on("point.mark", function(id, path){ //保存fileMap[id]
        var vehicleData = window.vehicleData;
        var gInfo = window.gInfo;
        if(!vehicleData.fileMap){
            vehicleData.fileMap = {};
        }
        conf.pointMap[id].photo = vehicleData.fileMap[id] = {
            path: path
        };
        if(gInfo.store){
            gInfo.store.saveVehicle(window.imageDir);
        }
    });
    
    $$.on("resetConf", function(){
        $$.each(conf.pointMap, function(point){
            point.photo = null;
        });
        $$.rootWidget.refresh();
    });

    conf.resetPoints = function(markedMap){
        //根据当前目录重新分配点位图
        $$.each(conf.pointMap, function(point){
            if(markedMap[point.id]){
                point.photo = window.vehicleData.fileMap[point.id];
            }else{
                if(window.vehicleData && window.vehicleData.fileMap){
                    delete window.vehicleData.fileMap[point.id];
                }
                point.photo = null;
            }
        });
        $$.rootWidget.refresh();
        if(window.gInfo.store){
            window.gInfo.store.saveVehicle(window.imageDir);
        }
    }
    
});
